//      config.cpp
//      
//      Copyright 2012 dimir <dimir@dimir-pc>
//      
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//      
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//      
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.
//      
//      


#include "config.h"


Config::Config(const std::string& path_to_config)
{
	std::ifstream config(path_to_config.c_str(), std::ifstream::in);
	while(!config.eof()){
		std::string config_line;
		config >> config_line;
		if (config_line.length()){
			if (config_line.find('=')){
				std::string tag = std::string(config_line, 0, config_line.find('='));
				std::string value = std::string(config_line, config_line.find('=') + 1, config_line.length() - config_line.find('=') - 1);
				this->tags_value[tag] = value;
			}
		}
	}
	config.close();
}

std::string Config::getValue(const std::string& tag_name){
	if (this->tags_value.count(tag_name)){
		return this->tags_value[tag_name];
	}else return std::string("");
}

std::string Config::getPathToMap(){
	return getValue(std::string(TAG_MAP));
}

std::string Config::getPathToPlayer1(){
	return getValue(std::string(TAG_PLAYER_1));
}

std::string Config::getPathToPlayer2(){
	return getValue(std::string(TAG_PLAYER_2));
}

std::string Config::getPathToPlayer1STDIN(){
	return getValue(std::string(TAG_PLAYER_1_STDIN));
}
std::string Config::getPathToPlayer1STDOUT(){
	return getValue(std::string(TAG_PLAYER_1_STDOUT));
}
std::string Config::getPathToPlayer2STDIN(){
	return getValue(std::string(TAG_PLAYER_2_STDIN));
}
std::string Config::getPathToPlayer2STDOUT(){
	return getValue(std::string(TAG_PLAYER_2_STDOUT));
}

std::string Config::getPathToChecker(){
	return getValue(std::string(TAG_CHECKER));
}

